package com.ruoyi.report.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.report.domain.ReportSchedule;
import com.ruoyi.report.service.IReportScheduleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报定时任务Controller
 * 
 * @author ruoyi
 * @date 2025-06-17
 */
@Controller
@RequestMapping("/report/schedule")
public class ReportScheduleController extends BaseController
{
    private String prefix = "report/schedule";

    @Autowired
    private IReportScheduleService reportScheduleService;

    @RequiresPermissions("report:schedule:view")
    @GetMapping()
    public String schedule()
    {
        return prefix + "/schedule";
    }

    /**
     * 查询报定时任务列表
     */
    @RequiresPermissions("report:schedule:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReportSchedule reportSchedule)
    {
        startPage();
        List<ReportSchedule> list = reportScheduleService.selectReportScheduleList(reportSchedule);
        return getDataTable(list);
    }

    /**
     * 导出报定时任务列表
     */
    @RequiresPermissions("report:schedule:export")
    @Log(title = "报定时任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReportSchedule reportSchedule)
    {
        List<ReportSchedule> list = reportScheduleService.selectReportScheduleList(reportSchedule);
        ExcelUtil<ReportSchedule> util = new ExcelUtil<ReportSchedule>(ReportSchedule.class);
        return util.exportExcel(list, "报定时任务数据");
    }

    /**
     * 新增报定时任务
     */
    @RequiresPermissions("report:schedule:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报定时任务
     */
    @RequiresPermissions("report:schedule:add")
    @Log(title = "报定时任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ReportSchedule reportSchedule)
    {
        return toAjax(reportScheduleService.insertReportSchedule(reportSchedule));
    }

    /**
     * 修改报定时任务
     */
    @RequiresPermissions("report:schedule:edit")
    @GetMapping("/edit/{scheduleId}")
    public String edit(@PathVariable("scheduleId") Long scheduleId, ModelMap mmap)
    {
        ReportSchedule reportSchedule = reportScheduleService.selectReportScheduleByScheduleId(scheduleId);
        mmap.put("reportSchedule", reportSchedule);
        return prefix + "/edit";
    }

    /**
     * 修改保存报定时任务
     */
    @RequiresPermissions("report:schedule:edit")
    @Log(title = "报定时任务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ReportSchedule reportSchedule)
    {
        return toAjax(reportScheduleService.updateReportSchedule(reportSchedule));
    }

    /**
     * 删除报定时任务
     */
    @RequiresPermissions("report:schedule:remove")
    @Log(title = "报定时任务", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(reportScheduleService.deleteReportScheduleByScheduleIds(ids));
    }
}
